<template>
  <el-form ref="dataForm" v-model="query" class="form" :rules="rules">
    <h3>注册</h3>
    <el-form-item label-width="0">
      <el-checkbox v-model="query.ck_007_sys_setting_3_20">允许所有人注册</el-checkbox>
      <el-checkbox v-model="query.ck_007_sys_setting_3_21">允许系统居民用户注册</el-checkbox>
      <el-checkbox v-model="query.ck_007_sys_setting_3_22">允许系统商业用户注册</el-checkbox>
      <el-checkbox v-model="query.ck_007_sys_setting_3_23">允许系统工业用户注册</el-checkbox>
    </el-form-item>
    <el-form-item label="在不允许范围内的注册提示语:" prop="registerTips">
      <el-input v-model="query.registerTips" style="width: 500px;" :maxlength="255" />
    </el-form-item>
    <el-form-item label="绑定校验:" prop="validateContent">
      <el-select v-model="query.validateContent" size="mini" disabled>
        <el-option :value="1" label="仅校验手机号" />
        <el-option :value="2" label="校验手机号和客户编号" />
        <el-option :value="3" label="校验手机号和客户名称" />
        <el-option :value="4" label="校验手机号、客户编号、客户名称" />
      </el-select>
    </el-form-item>
    <el-form-item v-if="query.ck_007_sys_setting_3_20" label="新用户注册信息:">
      <el-checkbox v-model="query.ck_007_sys_setting_sp4_10" checked disabled>手机号</el-checkbox>
      <el-checkbox v-model="query.ck_007_sys_setting_sp4_11" checked disabled>客户名称</el-checkbox>
      <el-checkbox v-model="query.ck_007_sys_setting_sp4_12">地址</el-checkbox>
      <el-checkbox v-model="query.ck_007_sys_setting_sp4_13">客户类型</el-checkbox>
      <el-checkbox v-model="query.ck_007_sys_setting_sp4_14">身份证</el-checkbox>
    </el-form-item>
    <el-divider />
    <h4>预约</h4>
    <el-form-item label="每日接受预约时间从:" prop="time">
      <el-time-picker
        v-model="time"
        is-range
        range-separator="至"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
        placeholder="选择时间范围"
        format="HH:mm"
      />
    </el-form-item>
    <el-form-item prop="wxUpMin" label-width="0">
      <el-checkbox v-model="checked" disabled>下单时间比预约时间至少提前 <el-input-number v-model="query.wxUpMin" size="mini" controls-position="right" :min="0" :max="5000" :precision="0" /></el-checkbox>
    </el-form-item>
    <el-form-item prop="ck_007_sys_setting_3_27">
      <el-checkbox v-model="query.ck_007_sys_setting_3_27">微信下单显示市价和优惠价</el-checkbox>
    </el-form-item>
    <el-form-item prop="ck_007_sys_setting_sp4_4">
      <el-checkbox v-model="query.ck_007_sys_setting_sp4_4">开启微信打赏</el-checkbox>
    </el-form-item>
    <el-form-item prop="anjian" label="会员中心显示:">
      <el-checkbox v-model="query.ck_007_sys_setting_sp4_7">随单安检</el-checkbox>
      <el-checkbox v-model="query.ck_007_sys_setting_sp4_8">定期安检</el-checkbox>
    </el-form-item>
  </el-form>
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    name: 'WechatTab',
    data() {
      return {
        time: [],
        checked: true,
        query: {
          registerTips: '',
          validateContent: 1,
          registerItem: [],
          wxUpMin: 30,
          anjian: [],
          ck_007_sys_setting_sp4_10: false,
          ck_007_sys_setting_sp4_11: false,
          ck_007_sys_setting_sp4_12: false,
          ck_007_sys_setting_sp4_13: false,
          ck_007_sys_setting_sp4_14: false,
          ck_007_sys_setting_3_20: false,
          ck_007_sys_setting_3_21: false,
          ck_007_sys_setting_3_22: false,
          ck_007_sys_setting_3_23: false,
          ck_007_sys_setting_3_27: false,
          ck_007_sys_setting_sp4_4: false,
          ck_007_sys_setting_sp4_7: false,
          ck_007_sys_setting_sp4_8: false
        },
        rules: {

        }
      }
    },
    computed: {
      ...mapGetters([
        'corpSettingData', 'userInfo'
      ])
    },
    created() {
      this.init()
    },
    methods: {
      init() {
        if (this.corpSettingData) {
          this.query.registerTips = this.corpSettingData.registerTips
          if (this.corpSettingData.wxLimitTime) {
            const limitTimes = this.corpSettingData.wxLimitTime.split('-')
            const startTime = limitTimes[0]
            const endTime = limitTimes[1]
            const year = new Date().getFullYear()
            const month = new Date().getMonth() + 1
            const date = new Date().getDate()
            this.time = [new Date(year, month, date, startTime.split(':')[0], startTime.split(':')[1]), new Date(year, month, date, endTime.split(':')[0], endTime.split(':')[1])]
          }
          if (this.corpSettingData.wxUpMin > 0) {
            this.query.wxUpMin = this.corpSettingData.wxUpMin >> 1
          }
          if (this.corpSettingData.wxUpMin & 0x01) {
            this.checked = true
          }
          // 微信注册校验设置
          if ((this.corpSettingData.sp3 >> 28 & 0x01) > 0 && (this.corpSettingData.sp3 >> 29 & 0x01) === 0 && (this.corpSettingData.sp3 >> 30 & 0x01) === 0) {
            // 仅校验手机选中
            this.query.validateContent = 1
          }
          if ((this.corpSettingData.sp3 >> 28 & 0x01) > 0 && (this.corpSettingData.sp3 >> 29 & 0x01) > 0 && (this.corpSettingData.sp3 >> 30 & 0x01) === 0) {
            // 校验手机号和客户编号选中
            this.query.validateContent = 2
          }
          if ((this.corpSettingData.sp3 >> 28 & 0x01) > 0 && (this.corpSettingData.sp3 >> 29 & 0x01) === 0 && (this.corpSettingData.sp3 >> 30 & 0x01) > 0) {
            // 校验手机好和客户名称选中
            this.query.validateContent = 3
          }
          if ((this.corpSettingData.sp3 >> 28 & 0x01) > 0 && (this.corpSettingData.sp3 >> 29 & 0x01) > 0 && (this.corpSettingData.sp3 >> 30 & 0x01) > 0) {
            // 校验手机号，客户编号，客户名称选中
            this.query.validateContent = 4
          }
          this.query.ck_007_sys_setting_3_20 = !!(this.corpSettingData.sp3 >> 20 & 0x01)
          this.query.ck_007_sys_setting_3_21 = !!(this.corpSettingData.sp3 >> 21 & 0x01)
          this.query.ck_007_sys_setting_3_22 = !!(this.corpSettingData.sp3 >> 22 & 0x01)
          this.query.ck_007_sys_setting_3_23 = !!(this.corpSettingData.sp3 >> 23 & 0x01)
          this.query.ck_007_sys_setting_sp4_12 = !!(this.corpSettingData.sp4 >> 12 & 0x01)
          this.query.ck_007_sys_setting_sp4_13 = !!(this.corpSettingData.sp4 >> 13 & 0x01)
          this.query.ck_007_sys_setting_sp4_14 = !!(this.corpSettingData.sp4 >> 14 & 0x01)
          this.query.ck_007_sys_setting_3_27 = !!(this.corpSettingData.sp3 >> 27 & 0x01)
          this.query.ck_007_sys_setting_sp4_4 = !!(this.corpSettingData.sp4 >> 4 & 0x01)
          this.query.ck_007_sys_setting_sp4_7 = !!(this.corpSettingData.sp4 >> 7 & 0x01)
          this.query.ck_007_sys_setting_sp4_8 = !!(this.corpSettingData.sp4 >> 8 & 0x01)
        }
      }

    }
  }
</script>

<style lang="scss" scoped>
.form {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
